package com.candy.candymember;

import com.candy.candycommon.utils.ApplicationContentUtils;
import com.candy.candymember.config.ApplicationContextInitializer01;
import com.candy.candymember.config.ApplicationContextInitializer04;
import com.candy.candymember.domain.*;
import com.candy.candymember2.Member2;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

@ComponentScan(value = {"com.candy.candymember.*", "com.candy.candymember2"})
@SpringBootApplication
@Import({Member3.class, Member4ImportSelector.class, Member5ImportBeanDefinitionRegister.class, Member6DeferredImportSelector.class})
public class CandyMemberApplication {

    public static void main(String[] args) {
//        SpringApplication.run(CandyMemberApplication.class, args);
        // ApplicationContextInitializer扩展点
        // 配置文件 > SPI > 启动方式
        // 相同的注册方式，可以通过 @Order 注解进行修饰，值越小则优先级越高
        SpringApplication springApplication = new SpringApplication(CandyMemberApplication.class);
        springApplication.addInitializers(new ApplicationContextInitializer01(), new ApplicationContextInitializer04());
        springApplication.run(args);

        for (int i = 0; i < 2; i++) {
            // 如何将bean加入到spring容器中，不仅仅是以下五种方式，还有很多方式，都是基于spring的扩展点搞的
            // @Configuration + @Bean
            System.out.println(ApplicationContentUtils.getBean(Member1.class));
            // @Component + @ComponentScan
            System.out.println(ApplicationContentUtils.getBean(Member2.class));
            // @Import
            System.out.println(ApplicationContentUtils.getBean(Member3.class)); // @Import
            System.out.println(ApplicationContentUtils.getBean(Member4.class)); // @Import + 实现ImportSelector接口
            System.out.println(ApplicationContentUtils.getBean(Member5.class)); // @Import + 实现ImportBeanDefinitionRegistrar接口
            System.out.println(ApplicationContentUtils.getBean(Member6.class)); // @Import + 实现DeferredImportSelector接口
            // @Configuration + @Bean + 实现FactoryBean接口
            System.out.println(ApplicationContentUtils.getBean(Member7.class));
            // @Component + 实现BeanDefinitionRegistryPostProcessor接口
            System.out.println(ApplicationContentUtils.getBean(Member8.class));
        }
    }

}
